<template>
  <div>
    <el-table :data="tableData" border style="width: 100%">
      <el-table-column fixed prop="id" label="编号" width="150">
      </el-table-column>
      <el-table-column prop="name" label="姓名" width="120"> </el-table-column>
      <el-table-column prop="alias" label="别名" width="120"> </el-table-column>
      <el-table-column prop="password" label="密码" width="120">
      </el-table-column>
      <el-table-column prop="email" label="邮箱" width="300"> </el-table-column>
      <el-table-column prop="estate" label="小区" width="120">
      </el-table-column>
      <el-table-column fixed="right" label="操作" width="100">
        <template slot-scope="scope">
          <el-button @click="editUser(scope.row)" type="text" size="small"
            >修改</el-button
          >
          <el-button type="text" size="small">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      background
      layout="prev, pager, next"
      page-size="5"
      :total="total"
      @current-change="page"
    >
    </el-pagination>
  </div>
</template>

<script>
export default {
  methods: {
    editUser(row) {
      console.log(row);
      this.$router.push({
        path:'/updateuser',
        query:{
          id:row.id
        }
      })
    },
    page(currentPage) {
      const _this = this;
      axios
        .get("http://localhost:8181/user/findAll/" + currentPage + "/5")
        .then(function (resp) {
          console.log(resp);
          _this.tableData = resp.data.content;
        });
    },
  },

  data() {
    return {
      total: null,
      tableData: [
        {
          id: 1,
          name: "王小虎",
          alias: "小王",
          password: "1234567",
          email: "wangxiaohu@163.com",
          estate: "滨文苑",
        },
        {
          id: 1,
          name: "王小虎",
          alias: "小王",
          password: "1234567",
          email: "wangxiaohu@163.com",
          estate: "滨文苑",
        },
        {
          id: 1,
          name: "王小虎",
          alias: "小王",
          password: "1234567",
          email: "wangxiaohu@163.com",
          estate: "滨文苑",
        },
        {
          id: 1,
          name: "王小虎",
          alias: "小王",
          password: "1234567",
          email: "wangxiaohu@163.com",
          estate: "滨文苑",
        },
      ],
    };
  },
  created() {
    alert("123");
    const _this = this;
    axios.get("http://localhost:8181/user/findAll/1/5").then(function (resp) {
      console.log(resp);
      _this.tableData = resp.data.content;
      _this.total = resp.data.totalElements;
      // _this.pageSize=resp.data.size;
    });
  },
};
</script>

// function currentPageUsers() {
//   alert("123");
//   const _this=this;
//   axios.get("http://localhost:8181/user/findAll/1/5").then(function(resp) {
//     console.log(resp);
//     _this.tableData=resp.data.content;
//   });
// }

// function newFunction(currentPage) {
//   const _this=this;
//   axios.get("http://localhost:8181/user/findAll/"+currentPage+"/5").then(function(resp) {
//     console.log(resp);
//     _this.tableData=resp.data.content;
//   });
// }
